import { Component } from '@angular/core';
import { NavController, NavParams, LoadingController, Events } from 'ionic-angular';
import { DeviceProvider } from '../../../providers/service/device'
/**
 * Generated class for the BadDetailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-bad-detail',
  templateUrl: 'bad-detail.html',
})
export class BadDetailPage {

  constructor(public navCtrl: NavController,
    public deviceProvider: DeviceProvider,
    public events: Events,
    public loadingCtrl: LoadingController,
     public navParams: NavParams) {
  }

  isReady = false;
  isError = false;
  isLoading = true;
  badObj:any = {};
  ionViewDidLoad() {
    this.isReady = true;
    //console.log('ionViewDidLoad BadDetailPage');
    this.deviceProvider.getBadDetail(this.navParams.data.id).then(res=>{
        //console.log(res);
        this.badObj = res;
        this.badObj.dealStatus = '1';
        this.isLoading = false;
    },err=>{
        this.isError = true;
        this.isLoading = false;
    })
  }

  //设置为已处理
  deal() {
    let loading = this.loadingCtrl.create({
        content: '操作中，请稍等'
      });
    loading.present();
    this.badObj.status = this.badObj.dealStatus;
    this.badObj.description = this.badObj.dealDescription;
    this.deviceProvider.updateBadDetail(this.badObj).then(res=>{
        this.events.publish('RF_BAD_ITEM', this.badObj);
        loading.dismiss();
    },err=>{
        loading.dismiss();
    })
  }

}
